#!/usr/bin/env python3
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration, EqualsSubstitution
from launch.conditions import IfCondition
from launch.actions import ExecuteProcess


def generate_launch_description():
    return LaunchDescription(
        [
            DeclareLaunchArgument(
                "mode",
                default_value="cli",
                description="Mode of connection control, cli or ui",
                choices=["cli", "ui"],
            ),
            Node(
                package="chassis",
                executable="connection_control",
                name="connection_control_node",
                output="screen",
            ),
            ExecuteProcess(
                cmd=[
                    "gnome-terminal",
                    "--",
                    "ros2",
                    "run",
                    "chassis",
                    "connection_input_cli.py",
                ],
                output="screen",
                condition=IfCondition(
                    EqualsSubstitution(LaunchConfiguration("mode"), "cli")
                ),
            ),
            Node(
                package="chassis",
                executable="connection_input_ui.py",
                name="input_node",
                output="screen",
                condition=IfCondition(
                    EqualsSubstitution(LaunchConfiguration("mode"), "ui")
                ),
            ),
        ]
    )
